package com.wubotao.algorithm;


public class ShellSort {
	public static void sort(int[] array) {
		int i, j, gap;
		int temp;
		int n = array.length;
		for (gap = n / 2; gap > 0; gap /= 2) {// 计算gap大小
			for (i = gap; i < n; i++) {// 将数据进行分组
				for (j = i - gap; j >= 0 && array[j] > array[j + gap]; j -= gap) {
					temp = array[j];
					array[j] = array[j + gap];
					array[j + gap] = temp;
				}
			}
		}
	}

	public static void main(String[] args) {
		int[] array = { 5, 69, 12, 3, 56, 789, 2, 5648, 23 };
		sort(array);// 注意为数组的个数
		for (int m = 0; m <= array.length - 1; m++) {
			System.out.print(array[m] + "\t");
		}
	}
}


